home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
031-040
/
amok32
/
patterns
/
patterns.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
2KB
|
56 lines
(**********************************************************************
:Program. Patterns.mod
:Contents. Procedure to test pattern matching of filenames
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.27d
:History. V1.0 [bne] 24.Dec.1989
:History. V1.1 [bne] 31.Dec.1989 (imports Str instead of StringOps)
**********************************************************************)
IMPLEMENTATION MODULE Patterns;
FROM Str IMPORT Length;
PROCEDURE Match (Pattern: ARRAY OF CHAR;
String: ARRAY OF CHAR): BOOLEAN;
VAR
MaxPat, MaxStr: INTEGER;
PROCEDURE Test (PatPos, StrPos: INTEGER): BOOLEAN;
BEGIN
IF PatPos = MaxPat THEN
IF StrPos = MaxStr THEN
RETURN TRUE
END;
ELSE
CASE Pattern[PatPos] OF
|"*":
RETURN Test (PatPos + 1, StrPos) OR
(StrPos < MaxStr) AND Test (PatPos, StrPos + 1)
|"?":
RETURN (StrPos < MaxStr) AND
Test (PatPos + 1, StrPos + 1)
ELSE
RETURN (StrPos < MaxStr) AND
(String[StrPos] = Pattern[PatPos]) AND
Test (PatPos + 1, StrPos + 1)
END;
END;
RETURN FALSE
END Test;
BEGIN
MaxPat:= Length (Pattern);
MaxStr:= Length (String);
RETURN Test (0, 0)
END Match;
END Patterns.